// dynamicAssetLoader.js
export function loadCSS(file) {
    return new Promise((resolve, reject) => {
      const link = document.createElement('link');
      link.rel = 'stylesheet';
      link.type = 'text/css';
      link.href = file;
      link.onload = () => resolve();
      link.onerror = () => reject(new Error(`CSS file ${file} failed to load`));
      document.head.appendChild(link);
    });
  }
  
  export function loadJS(file) {
    return new Promise((resolve, reject) => {
      const script = document.createElement('script');
      script.type = 'text/javascript';
      script.src = file;
      script.onload = () => resolve();
      script.onerror = () => reject(new Error(`JS file ${file} failed to load`));
      document.body.appendChild(script);
    });
  }
  
  export async function loadResources(resources) {
    for (const resource of resources) {
        if (resource.type === 'css') {
            await loadCSS(resource.file);
            // console.log('css加载成功')
        } else if (resource.type === 'js') {
            await loadJS(resource.file);
            // console.log('js加载成功')
        }
    }
}